package cn.edu.ctbu.login.util;

import java.util.Map;

public class ResultUtil {
    // 成功时的响应，带有数据和自定义消息
    public static <T> Result<T> ok(String msg, T object) {
        Result<T> result = new Result<>();
        result.setCode(1);
        result.setData(object);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result<T> ok(String msg) {
        Result<T> result = new Result<>();
        result.put("msg", msg);
        return result;
    }

    public static <T> Result<T> ok(Map<String, Object> map) {
        Result<T> result = new Result<>();
        result.putAll(map);
        return result;
    }

    public static <T> Result<T> ok(T object) {
        return ok("操作成功", object);
    }

    public static <T> Result<T> ok() {
        return ok("操作成功", null);
    }

    public static <T> Result<T> error() {
        return error(-1, "操作失败");
    }

    public static <T> Result<T> error(int code, String msg) {
        Result<T> result = new Result<>();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static <T> Result<T> error(String msg) {
        return error(-1, msg);
    }
}